package lc.activiti.contract.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lc.activiti.common.HttpRequestStatus;
import lc.activiti.common.LCExceptionUtils;
import lc.activiti.common.Result;
import lc.activiti.contract.service.IContractApprovalService;
import lc.activiti.contract.service.IContractAuditService;
import lc.activiti.model.SubApprovalModel;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequestMapping("/contractBrowseApprovalService")
@RestController
public class ConBrowseApprovalController {
	@Autowired
	private IContractApprovalService contractApprovalSerivce;
	@Autowired
	private IContractAuditService contractAuditService;
	
	@PostMapping("/contractBrowseAppSubmit")
	public Result<Object> contractBrowseAppSubmit(@RequestBody SubApprovalModel appModel){
		
		Result<Object> result=new Result<>();
		try {
			contractApprovalSerivce.browseAppSubmit(appModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			log.error("contractBrowseAppSubmit", e);
			return result;
		}
	}
	@PostMapping("/contBrowseApprovalSuccess")
	public Result<Object> contractBrowseApprovalSuccess(@RequestBody SubApprovalModel appModel){
		Result<Object> result=new Result<>();
		try {
			contractApprovalSerivce.browseApprovalSuccess(appModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			log.error("contBrowseApprovalSuccess", e);
			return result;
		}
	}
	@PostMapping("/contractBrowseApprovalReject")
	public Result<Object> contractBrowseApprovalReject(@RequestBody SubApprovalModel appModel){
		Result<Object> result=new Result<>();
		try {
			contractApprovalSerivce.browseApprovalReject(appModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			log.error("contractBrowseApprovalReject", e);
			return result;
		}
	}
	@PostMapping("/contractBrowseAuditSuccess")
	public Result<Object> contractBrowseAuditSuccess(@RequestBody SubApprovalModel appModel){
		Result<Object> result=new Result<>();
		try {
			contractAuditService.contractBrowseAuditSuccess(appModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			log.error("contractBrowseAuditSuccess", e);
			return result;
		}
	}
	@PostMapping("/contractBrowseAuditReject")
	public Result<Object> contractBrowseRejectSuccess(@RequestBody SubApprovalModel appModel){
		Result<Object> result=new Result<>();
		try {
			contractAuditService.contractBrowseAuditReject(appModel);
			result.setMessage(HttpRequestStatus.Sucess.getDesc());
			result.setStatus(HttpRequestStatus.Sucess.getStatus());
			return result;
		} catch (Exception e) {
			result.setMessage(LCExceptionUtils.getExpetionMessage(e));
			result.setStatus(HttpRequestStatus.Failed.getStatus());
			log.error("contractBrowseAuditReject", e);
			return result;
		}
	}
}
